<template>
    <div>
        <div class="comment-item" v-for="comment in comments" :key="comment.commentId">
            <div class="user-img">
                <img :src="`../imgs/users/${comment.userImg}`">
            </div>
            <div class="user-info">
                <div class="user-name">
                    <span>{{comment.username}}</span>
                    <div class="film-source">
                        <span class="star-img open"></span>
                        <span class="star-img open"></span>
                        <span class="star-img open"></span>
                        <span class="star-img close"></span>
                        <span class="star-img close"></span>
                        <span class="star-source">{{comment.userSource}}</span>
                    </div>
                </div>
                <div class="user-time">{{comment.createTime}}</div>
            </div>
            <div class="user-conent">
                {{comment.userMsg}}
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            comments: []
        };
    },
    methods: {
        getFilmComment(id) {
            $.ajax({
                url: "http://localhost/film-project/filmApi/loadComments.php",
                data: {
                    filmId: id
                },
                dataType: "json",
                success: ({ result }) => {
                    this.comments = result;
                }
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.getFilmComment(this.$root.$children[0].filmId);
        });
    }
};
</script>
<style lang="less" scoped>
.comment-item {
    display: grid;
    grid-template-columns: 1fr 6fr;
    grid-template-rows: auto auto;
    padding: 0rem 0.2rem 0.6rem 0.2rem;
    > .user-img {
        width: 100%;
        > img {
            width: 100%;
            height: auto;
            border-radius: 50%;
        }
    }
    > .user-info {
        font-size: 0.3rem;
        padding-left: 0.2rem;
        > .user-name {
            margin-top: 0.1rem;
            > .film-source {
                float: right;
            }
        }
        > .user-time {
            margin-top: 0.1rem;
            font-size: 0.26rem;
            color: @gray;
        }
    }
    > .user-conent {
        font-size: 0.24rem;
        text-indent: 0.56rem;
        line-height: 0.4rem;
        grid-column-start: 2;
        grid-column-end: 3;
        padding-left: 0.2rem;
    }
}
</style>